immodules: Move path code out of gtkrc
authorBenjamin Otte <otte@redhat.com>
Thu, 6 Oct 2016 17:59:53 +0000 (19:59 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 16 Oct 2016 16:17:21 +0000 (18:17 +0200)
gtk/gtkimmodule.c
gtk/gtkimmoduleprivate.h
gtk/queryimmodules.c

index 24a5f62302a047f01a1e4aea7f1ae003c16caabf..289cec06a070bc151900594b8bbd637b5d358d8a 100644 (file)
@@ -33,6 +33,7 @@
 #include <gmodule.h>
 #include "gtkimmoduleprivate.h"
 #include "gtkimcontextsimple.h"
+#include "gtkmodulesprivate.h"
 #include "gtksettings.h"
 #include "gtkprivate.h"
 #include "gtkutilsprivate.h"
@@ -63,8 +64,6 @@
 #define GDK_DEPRECATED
 #define GDK_DEPRECATED_FOR(f)
 
-#include "deprecated/gtkrc.h"
-
 /* We need to call getc() a lot in a loop. This is suboptimal,
  * as getc() does thread locking on the FILE it is given.
  * To optimize that, lock the file first, then call getc(),
@@ -332,12 +331,71 @@ add_builtin_module (const gchar             *module_name,
   return module;
 }
 
+/*
+ * gtk_get_im_module_path:
+ *
+ * Obtains the path in which to look for IM modules. See the documentation
+ * of the `GTK_PATH`
+ * environment variable for more details about looking up modules. This
+ * function is useful solely for utilities supplied with GTK+ and should
+ * not be used by applications under normal circumstances.
+ *
+ * Returns: (type filename): a newly-allocated string containing the
+ *    path in which to look for IM modules.
+ */
+gchar *
+gtk_get_im_module_path (void)
+{
+  gchar **paths = _gtk_get_module_path ("immodules");
+  gchar *result = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, paths);
+  g_strfreev (paths);
+
+  return result;
+}
+
+/*
+ * gtk_get_im_module_file:
+ *
+ * Obtains the path to the IM modules file. See the documentation
+ * of the `GTK_IM_MODULE_FILE`
+ * environment variable for more details.
+ *
+ * Returns: (type filename): a newly-allocated string containing the
+ *    name of the file listing the IM modules available for loading
+ */
+gchar *
+gtk_get_im_module_file (void)
+{
+  const gchar *var = g_getenv ("GTK_IM_MODULE_FILE");
+  gchar *result = NULL;
+
+  if (var)
+    result = g_strdup (var);
+
+  if (!result)
+    {
+      const gchar *var;
+      gchar *path;
+
+      var = g_getenv ("GTK_EXE_PREFIX");
+
+      if (var)
+        path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, "immodules.cache", NULL);
+      else
+        path = g_build_filename (_gtk_get_libdir (), "gtk-3.0", GTK_BINARY_VERSION, "immodules.cache", NULL);
+
+      return path;
+    }
+
+  return result;
+}
+
 static void
 gtk_im_module_initialize (void)
 {
   GString *line_buf = g_string_new (NULL);
   GString *tmp_buf = g_string_new (NULL);
-  gchar *filename = gtk_rc_get_im_module_file();
+  gchar *filename = gtk_get_im_module_file();
   FILE *file;
   gboolean have_error = FALSE;
 
index cae0dedc9438be2b6628816500ae7aa67630cc3d..1796e03902e6905109f05b3da344957d0124562b 100644 (file)
@@ -19,8 +19,8 @@
 #define __GTK_IM_MODULE_PRIVATE_H__
 
 #include <gdk/gdk.h>
-#include <gtk/gtkimcontext.h>
-#include <gtk/gtkimcontextinfo.h>
+#include "gtkimcontext.h"
+#include "gtkimcontextinfo.h"
 
 G_BEGIN_DECLS
 
@@ -29,6 +29,12 @@ void           _gtk_im_module_list                   (const GtkIMContextInfo ***
 GtkIMContext * _gtk_im_module_create                 (const gchar              *context_id);
 const gchar  * _gtk_im_module_get_default_context_id (void);
 
+/* Needs to be exported API for gtk-queryimmodules */
+GDK_AVAILABLE_IN_ALL
+gchar *        gtk_get_im_module_path                (void);
+GDK_AVAILABLE_IN_ALL
+gchar *        gtk_get_im_module_file                (void);
+
 G_END_DECLS
 
 #endif /* __GTK_IM_MODULE_PRIVATE_H__ */
index e9978fd3227852d34f56d0858770ccedc176dd31..fab90fe48af4104f21cee425944daae766498c1a 100644 (file)
 #endif
 
 #include "gtk/gtkimcontextinfo.h"
+#include "gtk/gtkimmoduleprivate.h"
 #include "gtk/gtkversion.h"
 #include "gtk/gtkutilsprivate.h"
 
-#include "gtk/deprecated/gtkrc.h"
-
 static void
 escape_string (GString *contents, const char *str)
 {
@@ -164,9 +163,7 @@ int main (int argc, char **argv)
 
   if (argc > 1 && strcmp (argv[1], "--update-cache") == 0)
     {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-      cache_file = gtk_rc_get_im_module_file ();
-G_GNUC_END_IGNORE_DEPRECATIONS
+      cache_file = gtk_get_im_module_file ();
       first_file = 2;
     }
 
@@ -184,9 +181,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       char **dirs;
       GHashTable *dirs_done;
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-      path = gtk_rc_get_im_module_path ();
-G_GNUC_END_IGNORE_DEPRECATIONS
+      path = gtk_get_im_module_path ();
 
       g_string_append_printf (contents, "# ModulesPath = %s\n#\n", path);